package hash;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 十八岁讨厌编程
 * @date 2025/6/27 21:14
 * @PROJECT_NAME leetcode
 * @description
 */

public class Solution242 {


    public boolean isAnagram(String s, String t) {
        char[] ss = s.toCharArray();
        Map<Character, Integer> scount = new HashMap<>();
        for (char word : ss) {
            if (scount.containsKey(word)) {
                scount.put(word, scount.get(word) + 1);
            } else {
                scount.put(word, 1);
            }
        }

        char[] tt = t.toCharArray();
        Map<Character, Integer> tcount = new HashMap<>();
        for (char word : tt) {
            if (tcount.containsKey(word)) {
                tcount.put(word, tcount.get(word) + 1);
            } else {
                tcount.put(word, 1);
            }
        }

        if (scount.size() != tcount.size()) return false;

        for (Map.Entry<Character, Integer> entry : scount.entrySet()) {
            Character key = entry.getKey();
            Integer value = entry.getValue();
            if (tcount.get(key) == null) return false;
            if (!tcount.get(key).equals(value)) return false;
        }

        return true;

    }


}
